package com.htudata.equipment.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.htudata.common.enums.RequestSeqEnum;
import com.htudata.convention.domain.ResponseResult;
import com.htudata.core.util.ResultGenerator;
import com.htudata.equipment.dao.EquipmentDao;
import com.htudata.equipment.service.EquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EquipmentServiceImpl implements EquipmentService {

  @Autowired
  private EquipmentDao equipmentDao;

  @Override
  public JSONArray getAllEquipmentReach() {
    return this.equipmentDao.getAllEquipmentReach();
  }

  @Override
  public String getAllEquipmentReachJSON() throws Exception{
    ResponseResult responseResult = null;
    try {
      responseResult = ResultGenerator.genResult(RequestSeqEnum.SEQ_013.getCode(), getAllEquipmentReach());
    } catch (Exception e) {
      throw e;
    } 
    String result = JSON.toJSONString(responseResult);
    return result;
  }

  @Override
  public JSONArray getEachEquipmentProportion() throws Exception {
    return this.equipmentDao.getEachEquipmentProportion();
  }

  @Override
  public String getEachEquipmentProportionJSON() throws Exception {
    ResponseResult responseResult = null;
    try {
      responseResult = ResultGenerator.genResult(RequestSeqEnum.SEQ_014.getCode(), getEachEquipmentProportion());
    } catch (Exception e) {
      throw e;
    } 
    String result = JSON.toJSONString(responseResult);
    return result;
  }

  @Override
  public JSONArray getEachEquipmentReach() throws Exception {
    return this.equipmentDao.getEachEquipmentReach();
  }

  @Override
  public String getEachEquipmentReachJSON() throws Exception {
    ResponseResult responseResult = null;
    try {
      responseResult = ResultGenerator.genResult(RequestSeqEnum.SEQ_015.getCode(), getEachEquipmentReach());
    } catch (Exception e) {
      throw e;
    } 
    String result = JSON.toJSONString(responseResult);
    return result;
  }

  @Override
  public JSONArray getEquipmentDetails() throws Exception {
    return this.equipmentDao.getEquipmentDetails();
  }

  @Override
  public String getEquipmentDetailsJSON() throws Exception{
    ResponseResult responseResult = null;
    try {
      responseResult = ResultGenerator.genResult(RequestSeqEnum.SEQ_016.getCode(), getEquipmentDetails());
    } catch (Exception e) {
      throw e;
    } 
    String result = JSON.toJSONString(responseResult);
    return result;
  }
}
